from radarssd_sql import *
import time

if __name__ == "__main__":
    conn = connect_db()
    cursor = conn.cursor()

    #先清空数据库
    # cursor.execute(build_cleardb_query())
    # conn.commit()

    #随机生成一系列信号，测试数据库写入性能
    start_time = time.time()

    #在已经插入的基础上继续插入，节约时间
    now_test_time = 1000*1000*1000
    last_test_time = 256*1000*1000

    test_time = now_test_time - last_test_time
    line_count = 0
    for i in range(test_time):
        cursor.execute(build_insert_query(i+last_test_time,i+1,i+2))

        line_count += 1
        if(line_count % 2048 == 0):
            conn.commit()
            print("inserted %d lines"%line_count)
    conn.commit()

    end_time = time.time()
    total_us = round(end_time-start_time,8)*1000000
    print("Insert",line_count,"signals")
    print("Total",total_us/1000000,"s, average",total_us/line_count,"us/signal")